package scalaLearning.part18

object CovariantContravariant {
  def main(args: Array[String]): Unit = {
    val t2:Temp2[Super]=new Temp2[Sub]("hello")//协变
    val t3:Temp3[Sub]=new Temp3[Super]("hello")//逆变
  }
}

class Super;

class Sub extends Super;

//不变
class Temp1[T](title:String){
  override def toString = {
    title
  }
}

//协变
class Temp2[+T](title:String){
  override def toString = {
    title
  }
}

//逆变
class Temp3[-T](title:String){
  override def toString = {
    title
  }
}